package task.manager;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * The user list class for the task manager.
 * 
 * @author Harrison Saylor, Aaron Mead, Marc Huet, Greg Ruskin
 * @version 1.0
 */
public class UserList implements Serializable {
	
	// Account preferences.
	//private SharedPreferences preferences;
	
	private static final long serialVersionUID = 1;
	private Map<String, String> users;
	
	/**
	 * UserList default constructor.
	 */
	public UserList() {
		users = new HashMap<String, String>();
	} // End of UserList default constructor.
	
	/**
	 * UserList constructor.
	 * 
	 * @param users HashMap of users.
	 */
	public UserList(Map<String,String> users){
		this.users = users;
	} // End of UserList constructor.
	
	/**
	 * Registers new users.
	 * 
	 * @param username User's account name.
	 * @param password User's password.
	 */
	public void registerNewUser(String username, String password){
    	users.put(username, password);
    } // End of registerNewUser method.
	
	/**
	 * Checks if the user has a valid account.
	 * 
	 * @param username User's account name.
	 * @param password User's password.
	 * @return True if username and password match, false otherwise.
	 */
	public boolean isValid(String username, String password){
		System.out.println(""+users);
		if(users.get(username)!=null){
			System.out.println("Here2");
			if(users.get(username).equals(password)){
				System.out.println("Here3");
				return true;
			} // End of if statement.
		} // End of if statement.
		return false;
	} // End of isValid method.
	
	public Map<String, String> getUserList(){
		return users;
	}
	
} // End of UserList class.
